package cn.sumpu.app.coolsk.web.mvc.member;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.sumpu.app.coolsk.bean.ImageWeb;
import cn.sumpu.app.coolsk.biz.ContentBiz;
import cn.sumpu.app.coolsk.biz.DiscussBiz;
import cn.sumpu.app.coolsk.biz.HotelRoomBiz;
import cn.sumpu.app.coolsk.biz.IdentifierBiz;
import cn.sumpu.app.coolsk.biz.ImageBiz;
import cn.sumpu.app.coolsk.biz.MailBiz;
import cn.sumpu.app.coolsk.biz.MemberBiz;
import cn.sumpu.app.coolsk.biz.OrderBiz;
import cn.sumpu.app.coolsk.biz.ProductBiz;
import cn.sumpu.app.coolsk.biz.ScenicBiz;
import cn.sumpu.app.coolsk.biz.TripBiz;
import cn.sumpu.app.coolsk.biz.WeiboBiz;
import cn.sumpu.app.coolsk.constant.Constant;
import cn.sumpu.app.coolsk.domain.CardNum;
import cn.sumpu.app.coolsk.domain.Content;
import cn.sumpu.app.coolsk.domain.Discuss;
import cn.sumpu.app.coolsk.domain.Hotel;
import cn.sumpu.app.coolsk.domain.Keep;
import cn.sumpu.app.coolsk.domain.Member;
import cn.sumpu.app.coolsk.domain.MemberDetail;
import cn.sumpu.app.coolsk.domain.MemberTicker;
import cn.sumpu.app.coolsk.domain.OnLineUserListener;
import cn.sumpu.app.coolsk.domain.OutUser;
import cn.sumpu.app.coolsk.domain.Product;
import cn.sumpu.app.coolsk.domain.Scenic;
import cn.sumpu.app.coolsk.domain.Trip;
import cn.sumpu.app.coolsk.domain.TripDay;
import cn.sumpu.app.coolsk.exception.AppBusinessException;
import cn.sumpu.app.coolsk.util.VerifyCode;
import cn.sumpu.app.coolsk.web.util.UCUtil;
import cn.sumpu.toolkit.common.page.PageModel;
import cn.sumpu.toolkit.common.util.Common;
import cn.sumpu.toolkit.weibo.AccessUser;

@Controller
public class MemberController {
    private final static Logger logger = LoggerFactory.getLogger(MemberController.class);

    @Autowired
    private MemberBiz           memberBiz;
    @Autowired
    private WeiboBiz            weiboBiz;
    @Autowired
    private ImageBiz            imageBiz;
    @Autowired
    private OrderBiz            orderBiz;
    @Autowired
    private TripBiz             tripBiz;
    @Autowired
    private IdentifierBiz       idBiz;
    @Autowired
    private HotelRoomBiz        hotelRoomBiz;
    @Autowired
    private DiscussBiz          discussBiz;
    @Autowired
    private ScenicBiz           scenicBiz;
    @Autowired
    private ProductBiz          productBiz;
    @Autowired
    private ContentBiz          contentBiz;
    @Autowired
    private MailBiz             mailBiz;

    /**
     * 登录页面
     * 
     * @param request
     * @param memberOutAccount
     * @return
     * @throws AppBusinessException
     */
    @RequestMapping(value = "/login.htm")
    public String enterLogin(HttpServletRequest request) throws AppBusinessException {
        String hisUrl = request.getHeader("Referer");
        request.setAttribute("hisUrl", hisUrl);
        String loginReferer = request.getHeader("referer");
        request.getSession().setAttribute("loginReferer", loginReferer);
        // request.setAttribute("memberOutAccount", memberOutAccount);
        return "login";
    }

    /**
     * 登录
     * 
     * @author vimple
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/loginOn.htm")
    public String login(HttpServletRequest request, HttpServletResponse response, String hisUrl) {
        try {

            String result = memberBiz.login(request, response);
            if ("dailylogin".equals(result)) {
                /*String loginReferer = (String) request.getSession()
                		.getAttribute("loginReferer");*/

                //同步登录Coolgy
                //				UCUtil.loginCoolgy(request, response);

                if (Common.notEmptyStr(hisUrl)) {
                    response.sendRedirect(hisUrl);
                } else {
                    response.sendRedirect("/");
                }
            } else if ("noRegister".equals(result)) {
                request.setAttribute("loginError", "登录失败，用户名或密码输入错误或用户名不存在请马上注册");
                return "login";
            }
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("[/loginOn.htm] fail.", e);
            }
        }
        return null;
    }

    /**
     * 退出
     * 
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/logout.htm", method = RequestMethod.GET)
    public String logout(HttpServletRequest request, HttpServletResponse response) {
        try {
            request.getSession(true).removeAttribute("onlineUser");

            //同步退出Coolgy
            //			UCUtil.logoutCoolgy(request, response);

            response.sendRedirect("/");
        } catch (Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error("[/logout.htm] fail.", e);
            }
        }
        return null;
    }

    /**
     * 注册页面
     * 
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/register.htm")
    public String register(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String registerReferer = request.getHeader("referer");
        request.getSession().setAttribute("registerReferer", registerReferer);
        return "register";
    }

    /**
     * 注册页面(手机)
     * 
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/rPhone.htm")
    public String rPhone(HttpServletRequest request, HttpServletResponse response) throws IOException {
        return "registerPhone";
    }

    /**
     * // 注册
     * 
     * @param member
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/registerOn.htm", method = RequestMethod.POST)
    public String registerOn(String vCode, Member member, HttpServletRequest request, HttpServletResponse response, String outUserReg) {

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter pw = null;
        try {
            String sessionCode = String.valueOf(request.getSession().getAttribute("code"));
            pw = response.getWriter();
            if (Common.notEmptyStr(vCode) && !vCode.equals(sessionCode)) {
                pw.print("codeError");
                return null;
            } else {
                // 注册信息
                // 发送验证邮箱
                String path = request.getContextPath();
                String emailPath = "http://www.coolsk.com/";
                member.setRegisterIP(request.getRemoteAddr());
                member.setLoginIP(request.getRemoteAddr());

                if (Common.notEmptyStr(outUserReg)) {
                    AccessUser accessUser = (AccessUser) request.getSession().getAttribute("accessUser");
                    if (accessUser != null) {
                        member.setAccessUser(accessUser);
                    }
                }
                String passWord = member.getPassword();
                // 注册
                Member memeberSession = memberBiz.register(emailPath, member);
                request.getSession(true).setAttribute("onlineUser", new OnLineUserListener(memeberSession));
                request.getSession().removeAttribute("accessUser");

                //异步注册Coolgy
                UCUtil.rsyncRegisterCoolgy(member.getNickname(), passWord, member.getEmail());

                // 来源
                String registerReferer = (String) request.getSession().getAttribute("registerReferer");
                if (Common.notEmptyStr(registerReferer)) {
                    pw.print(registerReferer);
                } else {
                    pw.print("member.htm");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            pw.print("error");
        }
        return null;
    }

    /**
     * 邮箱验证
     * 
     * @param request
     * @param response
     * @throws AppBusinessException
     */
    @RequestMapping(value = "/checkEmail.htm")
    public void checkEmail(HttpServletRequest request, HttpServletResponse response) throws AppBusinessException {
        String email = request.getParameter("email");
        if (Common.empty(email))
            return;
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter pw = null;
        try {
            pw = response.getWriter();
            Member m = memberBiz.getMemberEmail(email);
            if (m != null) {
                pw.print(false);
            } else {
                pw.print(true);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 昵称验证
     * 
     * @param request
     * @param response
     * @param nickname
     * @throws AppBusinessException
     */
    @RequestMapping(value = "/checkNickname.htm")
    public void ckNickname(HttpServletRequest request, HttpServletResponse response, String nickname) throws AppBusinessException {
        if (Common.empty(nickname))
            return;
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter pw = null;
        try {
            pw = response.getWriter();
            Member m = memberBiz.getMemberNickName(nickname);
            if (Common.empty(m)) {
                pw.print(true);
            } else {
                pw.print(false);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * // 手机验证[注册]
     * 
     * @param phone
     * @param request
     * @param response
     * @throws AppBusinessException
     */
    @RequestMapping(value = "/checkPhone.htm")
    public void checkPhone(String phone, HttpServletRequest request, HttpServletResponse response) throws AppBusinessException {
        if (Common.empty(phone))
            return;
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter pw = null;
        try {
            pw = response.getWriter();
            Member m = memberBiz.getMemberPhone(phone);
            if (Common.empty(m)) {
                pw.print(true);
            } else {
                pw.print(false);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // 验证会员卡
    @RequestMapping(value = "/checkCardNum.htm")
    public void checkCardNum(String cardNum, HttpServletRequest request, HttpServletResponse response) throws AppBusinessException {
        if (Common.empty(cardNum))
            return;
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter pw = null;
        try {
            pw = response.getWriter();
            CardNum card = memberBiz.getCardNum(cardNum);
            if (Common.empty(card)) {
                pw.print(false);
            } else {
                pw.print(true);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * // 获取验证码图
     * 
     * @param phone
     * @param request
     * @param response
     * @throws AppBusinessException
     */
    @RequestMapping(value = "/verifyCode.htm", method = RequestMethod.GET)
    public String verifyCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
        // 设置ContentType:
        response.setContentType("image/jpeg");
        response.setHeader("Cache-Control", "no-cache");
        // 输出到ServletOutputStream:
        ServletOutputStream output = response.getOutputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        // 验证码类
        VerifyCode verifyCode = new VerifyCode();
        ImageIO.write(verifyCode.creatImage(), "jpeg", baos);
        output.write(baos.toByteArray());
        output.flush();
        // 储存验证码在session
        request.getSession().setAttribute("code", verifyCode.sRand);
        return null;
    }

    /**
     * // 修改密码
     * 
     * @param request
     * @param response
     * @throws AppBusinessException
     */
    @RequestMapping(value = "/ModifyPw.htm")
    public void ModifyPw(String newPassWord, HttpServletRequest request, HttpServletResponse response) throws AppBusinessException {
        try {
            response.setContentType("text/html; charset=UTF-8");
            PrintWriter out = response.getWriter();
            OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
            Member m = onLineUserListener.getMember();
            if (Common.notEmptyStr(m.getId()) && Common.notEmptyStr(newPassWord) && m != null && m.getEnabled()) {
                Member member = new Member();
                member.setId(m.getId());
                member.setPassword(Common.md5(Common.md5(newPassWord)));
                memberBiz.update(member);
                out.print("success");
            } else {
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    // 密码验证
    @RequestMapping(value = "/checkPassword.htm", method = RequestMethod.GET)
    public void checkPassword(HttpServletRequest request, HttpServletResponse response) throws AppBusinessException {
        String password = request.getParameter("oldPassWord");
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (Common.empty(password))
            return;
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter pw = null;
        try {
            pw = response.getWriter();
            Member member = memberBiz.getMemberByNick(password, (onLineUserListener.getMember().getNickname()));
            boolean pswNotExist = false;
            if (member != null) {
                pswNotExist = true;
            }
            pw.print(pswNotExist);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 会员主页()
     * 
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/member.htm")
    public String member(HttpServletRequest request, HttpServletResponse response) throws IOException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            try {

                Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
                PageModel myDisModel = discussBiz.getAllDiscuss(3, 1, onLineUserListener.getMember().getId());
                List<Content> pushForMe = contentBiz.getContentByChannel("9a40ba36-5c8f-4ac7-be87-3e946f3e597c", 6);
                request.setAttribute("pushForMe", pushForMe);
                request.setAttribute("member", member);
                request.setAttribute("myDisModel", myDisModel);
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
            return "v1/member/member";
        } else {
            return null;
        }

    }

    /**
     * 头像修改()
     * 
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/memberAva.htm")
    public String memberAva(HttpServletRequest request, HttpServletResponse response) throws IOException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            try {
                Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
                request.setAttribute("member", member);
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
            return "v1/member/memberAva";
        } else {
            return null;
        }

    }

    /**
     * 联系修改()
     * 
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/memberCon.htm")
    public String memberCon(HttpServletRequest request, HttpServletResponse response) throws IOException {

        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            try {
                Member memberInfo = memberBiz.getMemberById(onLineUserListener.getMember().getId());
                MemberDetail memberDetail = memberBiz.getMemberDetailById(onLineUserListener.getMember().getId());
                request.setAttribute("member", memberInfo);
                request.setAttribute("memberDetail", memberDetail);
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
            return "v1/member/memberCon";
        } else {
            return null;
        }

    }

    /**
     * 保存联系方式
     * 
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/saveMemberCon.htm")
    public String saveMemberCon(MemberDetail memberDetail, Member member, HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter pw = null;
        try {
            pw = response.getWriter();
            // 更新资料
            memberBiz.updateMemberDetail(memberDetail, member);
            pw.print("success");

        } catch (Exception e) {
            e.printStackTrace();
            pw.print("error");
        }
        return null;

    }

    /**
     * 
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/memberMain.htm")
    public String memberMain(HttpServletRequest request, HttpServletResponse response) throws IOException {
        return "v1/member/memberMain";
    }

    /**
     * 信息修改()
     * 
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/memberInfor.htm")
    public String memberInfor(HttpServletRequest request, HttpServletResponse response) throws IOException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            try {
                Member memberInfo = memberBiz.getMemberById(onLineUserListener.getMember().getId());
                MemberDetail memberDetail = memberBiz.getMemberDetailById(onLineUserListener.getMember().getId());
                request.setAttribute("member", memberInfo);
                request.setAttribute("memberDetail", memberDetail);
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
            return "v1/member/memberInfor";
        } else {
            return null;
        }
    }

    /**
     * 密码修改()
     * 
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/memberMpw.htm")
    public String memberMpw(HttpServletRequest request, HttpServletResponse response) throws IOException {
        return "v1/member/memberMpw";
    }

    /**
     * 取票人信息()
     * 
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/memberOth.htm")
    public String memberOth(HttpServletRequest request, HttpServletResponse response) throws IOException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            try {
                List<MemberTicker> tickerList = memberBiz.getTickerListById(onLineUserListener.getMember().getId());
                request.setAttribute("tickerList", tickerList);
                Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
                request.setAttribute("member", member);
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
            return "v1/member/memberOth";
        } else {
            return null;
        }

    }

    /**
     * 新浪微博登录
     * 
     * @param response
     * @throws IOException
     * @throws AppBusinessException
     */
    @RequestMapping(value = "/sinaLogin.htm")
    public void sinaLogin(HttpServletResponse response) throws IOException, AppBusinessException {
        response.sendRedirect(weiboBiz.requestOauthSina());
    }

    /**
     * 新浪微博登录回调处理
     * 
     * @param oauth_verifier
     * @param request
     * @param response
     * @return
     * @throws AppBusinessException
     * @throws IOException
     */
    @RequestMapping(value = "/sinaCallBack.htm")
    public String sinaCallBack(String oauth_verifier, HttpServletRequest request, HttpServletResponse response) throws AppBusinessException, IOException {
        AccessUser accessUser = memberBiz.sinaLogin(oauth_verifier);
        String respUrl = memberBiz.outLogin(accessUser, request);

        OutUser outUser = (OutUser) request.getAttribute("outUser");
        if ("login".equals(respUrl)) {
            response.sendRedirect("loginOn.htm?om=" + outUser.getMember());
        }
        return respUrl;
    }

    /**
     * 腾讯微博登录
     * 
     * @param response
     * @throws IOException
     * @throws AppBusinessException
     */
    @RequestMapping(value = "/tencentLogin.htm")
    public void tencentLogin(HttpServletResponse response) throws IOException, AppBusinessException {
        response.sendRedirect(weiboBiz.requestOauthTencent());
    }

    /**
     * 腾讯微博登录回调处理
     * 
     * @param oauth_verifier
     * @param request
     * @param response
     * @return
     * @throws AppBusinessException
     * @throws IOException
     */
    @RequestMapping(value = "/tencentCallBack.htm")
    public String tencentCallBack(String oauth_verifier, HttpServletRequest request, HttpServletResponse response) throws AppBusinessException, IOException {
        AccessUser accessUser = memberBiz.tencentLogin(oauth_verifier);
        String respUrl = memberBiz.outLogin(accessUser, request);
        OutUser outUser = (OutUser) request.getAttribute("outUser");
        if ("login".equals(respUrl)) {
            response.sendRedirect("loginOn.htm?om=" + outUser.getMember());
        }
        return respUrl;
    }

    /**
     * 腾讯QQ登录回调
     * 
     * @param accessUser
     * @param request
     * @param response
     * @return
     * @throws AppBusinessException
     * @throws IOException
     */
    @RequestMapping(value = "/qqLoginCallback.htm")
    public String qqLoginCallback(AccessUser accessUser, HttpServletRequest request, HttpServletResponse response) throws AppBusinessException, IOException {
        accessUser.setDesc("tencentQQ");
        accessUser.setAccessSecret("");
        String respUrl = memberBiz.outLogin(accessUser, request);
        OutUser outUser = (OutUser) request.getAttribute("outUser");
        if ("login".equals(respUrl)) {
            response.sendRedirect("loginOn.htm?om=" + outUser.getMember());
        }
        return respUrl;
    }

    /**
     * 更新资料
     * 
     * @param memberDetail
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/updateMInfor.htm", method = RequestMethod.POST)
    public String updateMInfor(MemberDetail memberDetail, Member member, HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter pw = null;
        try {
            pw = response.getWriter();
            // 更新资料
            memberBiz.updateMemberDetail(memberDetail, member);
            pw.print("success");

        } catch (Exception e) {
            e.printStackTrace();
            pw.print("error");
        }
        return null;
    }

    /**
     * 上传头像
     * 
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/uploadAvaImg.htm")
    public String uploadAvaImg(HttpServletRequest request, HttpServletResponse response) throws IOException {

        response.setContentType("text/html; charset=UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        PrintWriter pw = null;
        try {
            ImageWeb imageWeb = imageBiz.uploadOneImg(request, Constant.IMAGE_PATH_AVATAR);
            OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
            Member member = onLineUserListener.getMember();
            member.setImageServer(imageWeb.getImageServer());
            member.setAvatar(imageWeb.getImageUrl());
            memberBiz.updateMemberDetail(null, member);
            pw = response.getWriter();
            pw.print(JSONObject.fromObject(imageWeb));
        } catch (Exception e) {
            pw = response.getWriter();
            pw.print("error");
            if (logger.isErrorEnabled()) {
                logger.error("Add imgAvatar failure.", e);
            }
        }
        return null;
    }

    /**
     * 我的订单
     * 
     * @param page
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/myOrder.htm")
    public String myOrder(Integer page, HttpServletRequest request, HttpServletResponse response) throws IOException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            try {
                if (page == null)
                    page = 1;
                Integer pagesize = 5;
                PageModel orderModel = orderBiz.getOrderListByMemberId(page, pagesize, onLineUserListener.getMember().getId());
                request.setAttribute("orderModel", orderModel);
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
            return "v1/member/myOrder";
        } else {
            return null;
        }
    }

    /**
     * 我的收藏
     */
    @RequestMapping(value = "/myKeep.htm")
    public String myKeep(Integer page, HttpServletRequest request, HttpServletResponse response) throws IOException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            try {
                if (page == null)
                    page = 1;
                Integer pagesize = 5;
                PageModel keepModel = memberBiz.getKeepListByMid(page, pagesize, onLineUserListener.getMember().getId());
                request.setAttribute("keepModel", keepModel);
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
            return "v1/member/myKeep";
        } else {
            return null;
        }
    }

    /**
     * 我的积分
     */
    @RequestMapping(value = "/myPoint.htm")
    public String myPoint(Integer page, HttpServletRequest request, HttpServletResponse response) throws IOException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            try {
                if (page == null)
                    page = 1;
                Integer pagesize = 15;
                PageModel pointModel = memberBiz.getPointListByMid(page, pagesize, onLineUserListener.getMember().getId());
                request.setAttribute("pointModel", pointModel);
                Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
                request.setAttribute("member", member);
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
            return "v1/member/myPoint";
        } else {
            return null;
        }
    }

    // 增加点评
    /*
     * @RequestMapping(value = "/dis.htm", method = RequestMethod.POST) public
     * String discuss(Discuss discuss, HttpServletRequest request,
     * HttpServletResponse response) throws AppBusinessException {
     * response.setContentType("text/html; charset=UTF-8"); PrintWriter pw =
     * null; try { OnLineUserListener onLineUserListener = (OnLineUserListener)
     * request.getSession().getAttribute("onlineUser");
     * if(onLineUserListener!=null){ pw = response.getWriter();
     * discuss.setMember(onLineUserListener.getMember().getId());
     * memberBiz.instertDiscuss(discuss); pw.print("success"); } } catch
     * (IOException e) { e.printStackTrace(); } return null; }
     */

    // //////////////////////////////////////////////华丽的分界线////////////////////////////////////////////////

    /**
     * 我的点评
     */
    @RequestMapping(value = "/myCmt.htm")
    public String myCmt(Integer page, HttpServletRequest request, HttpServletResponse response) throws IOException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            try {
                if (page == null)
                    page = 1;
                Integer pagesize = 5;
                PageModel disModel = memberBiz.getDisListByMid(pagesize, page, onLineUserListener.getMember().getId());
                request.setAttribute("disModel", disModel);
                request.setAttribute("member", onLineUserListener.getMember());
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
            return "v1/member/myCmt";
        } else {
            return null;
        }
    }

    /* 我要点评 */
    @RequestMapping(value = "/disCmt.htm")
    public String disCmt(String id, String ot, HttpServletRequest request, HttpServletResponse response) throws IOException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            try {
                if (ot.equals("hotel")) {
                    // 酒店
                    Hotel hotel = hotelRoomBiz.getHotelById(id);
                    request.setAttribute("owner", hotel);
                    request.setAttribute("ot", ot);
                } else if (ot.equals("att")) {
                    // 景点
                    Scenic scenic = scenicBiz.getScenicById(id);
                    request.setAttribute("owner", scenic);
                    request.setAttribute("ot", ot);
                } else if (ot.equals("product")) {
                    // 产品
                    Product product = productBiz.getProductById(id);
                    request.setAttribute("owner", product);
                    request.setAttribute("ot", ot);
                }
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
            return "v1/disCmt/disCmt";
        } else {
            return null;
        }
    }

    @RequestMapping(value = "/disTest.htm")
    public String disTest(String id, String ot, HttpServletRequest request, HttpServletResponse response) throws IOException {
        return "v1/disCmt/disTest";
    }

    /* 保存点评 */
    @RequestMapping(value = "/saveDiscmt.htm", method = RequestMethod.POST)
    public String saveDiscmt(Discuss discuss, HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter pw = null;
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            try {
                pw = response.getWriter();
                // 增加点评
                discuss.setMember(onLineUserListener.getMember().getId());
                discuss.setIsAudit("00");
                discussBiz.insterDis(discuss);
                pw.print("success");

            } catch (Exception e) {
                e.printStackTrace();
                pw.print("error");
            }
        }
        return null;
    }

    /* 我要收藏 */
    @RequestMapping(value = "/saveKeep.htm", method = RequestMethod.POST)
    public String saveKeep(Keep keep, HttpServletRequest request, HttpServletResponse response) throws AppBusinessException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            response.setContentType("text/html; charset=UTF-8");
            PrintWriter pw = null;
            try {

                pw = response.getWriter();
                keep.setCreateMember(onLineUserListener.getMember().getId());
                Keep keepX = memberBiz.getKeep(keep);
                if (keepX == null) {
                    memberBiz.keep(keep);
                    pw.print("success");
                } else {
                    pw.print("error");
                }

            } catch (Exception e) {
                try {
                    pw = response.getWriter();
                    pw.print("error");
                } catch (IOException e1) {
                    e1.printStackTrace();
                }

                e.printStackTrace();
            }
        }
        return null;
    }

    // 点评页面
    @RequestMapping(value = "/cmtSus.htm")
    public String cmtSus(String id, HttpServletRequest request, HttpServletResponse response) throws IOException {

        request.setAttribute("id", id);
        return "v1/disCmt/cmtSus";
    }

    // 点评底页
    @RequestMapping(value = "/disCmtDet.htm")
    public String disCmtDet(String id, HttpServletRequest request, HttpServletResponse response) throws IOException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pageSize", 8);
        if (onLineUserListener != null) {
            try {
                Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
                Discuss discuss = discussBiz.getDiscussById(id);

                if (discuss.getOwnerType().equals("hotel")) {
                    // 酒店    
                    Hotel hotel = hotelRoomBiz.getHotelById(discuss.getOwner());
                    map.put("owner", hotel.getId());
                    map.put("ownerType", "hotel");
                    List<Discuss> discussList = discussBiz.getDiscussListByObj(map);
                    request.setAttribute("discussList", discussList);
                    request.setAttribute("owner", hotel);
                    request.setAttribute("ownerType", "hotel");
                    // request.setAttribute("content", hotel.getDescText());
                } else if (discuss.getOwnerType().equals("att")) {
                    // 景点
                    Scenic scenic = scenicBiz.getScenicById(discuss.getOwner());
                    map.put("owner", scenic.getId());
                    map.put("ownerType", "att");
                    request.setAttribute("owner", scenic);
                    request.setAttribute("ownerType", "att");
                    List<Discuss> discussList = discussBiz.getDiscussListByObj(map);
                    request.setAttribute("discussList", discussList);
                    // request.setAttribute("content", scenic.getDescText());
                } else if (discuss.getOwnerType().equals("product")) {
                    // 产品
                    Product product = productBiz.getProductById(discuss.getOwner());
                    map.put("owner", product.getId());
                    map.put("ownerType", "product");
                    request.setAttribute("owner", product);
                    request.setAttribute("ownerType", "product");
                    List<Discuss> discussList = discussBiz.getDiscussListByObj(map);
                    request.setAttribute("discussList", discussList);
                    // request.setAttribute("content", product.getSpecial());

                }
                request.setAttribute("discuss", discuss);
                request.setAttribute("member", member);
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
            return "v1/disCmt/disCmtDet";
        }
        return null;
    }

    // 我的行程
    @RequestMapping(value = "/myTrip.htm")
    public String myTrip(Integer pageK, Integer pageT, HttpServletRequest request, HttpServletResponse response) throws IOException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            try {
                if (pageK == null)
                    pageK = 1;
                if (pageT == null)
                    pageT = 1;
                Integer pagesize = 5;
                PageModel keepModel = memberBiz.getKeepListByMid(pageK, pagesize, onLineUserListener.getMember().getId());
                PageModel tripModel = tripBiz.getTripListByMid(pageT, pagesize, onLineUserListener.getMember().getId());
                // 特色指南
                List<Content> teSeZhiNan = contentBiz.getTripByChannel("2c686273-d946-4ca7-9fdb-3232d12cea71", 10);
                request.setAttribute("teSeZhiNan", teSeZhiNan);
                request.setAttribute("tripModel", tripModel);
                request.setAttribute("keepModel", keepModel);
                request.setAttribute("pageK", pageK);
                request.setAttribute("pageT", pageT);
                // keepModel.getTotalPage()
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
            return "v1/trip/myTrip";
        } else {
            return null;
        }
    }

    // 保存行程
    @RequestMapping(value = "/saveMyTrip.htm")
    public String saveTrip(Trip trip, String tripDayList, HttpServletRequest request, HttpServletResponse response) throws IOException {

        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            response.setContentType("text/plain; charset=utf-8");
            PrintWriter pw = null;
            try {
                trip.setId(idBiz.generateId("coolsk_trip"));
                trip.setMember(onLineUserListener.getMember().getId());
                // 行程
                tripBiz.insterTrip(trip);
                JSONArray tripDayListArray = JSONArray.fromObject(tripDayList);
                for (Object object : tripDayListArray) {
                    // 行程时间内容
                    JSONObject jsonObj = JSONObject.fromObject(object);
                    TripDay tripDay = (TripDay) JSONObject.toBean(jsonObj, TripDay.class);
                    tripDay.setTripId(trip.getId());
                    //第一天的图片赋值给行程封面
                    if (tripDay.getDay() == 1) {
                        trip.setCover(tripDay.getImage());
                        tripBiz.updateTrip(trip);
                    }
                    tripBiz.insterTripDay(tripDay);
                }
                pw = response.getWriter();
                pw.print("success");
            }

            catch (AppBusinessException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    // 查看详细页面
    @RequestMapping(value = "/viewTripByTid.htm")
    public String viewDetielByTrip(Integer pageK, Integer pageT, String id, HttpServletRequest request, HttpServletResponse response) throws IOException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            try {
                if (pageK == null)
                    pageK = 1;
                if (pageT == null)
                    pageT = 1;
                Integer pagesize = 5;
                PageModel keepModel = memberBiz.getKeepListByMid(pageK, pagesize, onLineUserListener.getMember().getId());
                PageModel tripModel = tripBiz.getTripListByMid(pageT, pagesize, onLineUserListener.getMember().getId());
                request.setAttribute("tripModel", tripModel);
                request.setAttribute("keepModel", keepModel);

                Trip trip = tripBiz.selectTripById(id);
                Integer day = trip.getDays();
                List<TripDay> daysList = new ArrayList<TripDay>();
                for (int i = 1; i <= day; i++) {
                    TripDay tripDay = new TripDay();
                    tripDay.setDay(i);
                    daysList.add(tripDay);
                }
                // 特色指南
                List<Content> teSeZhiNan = contentBiz.getTripByChannel("2c686273-d946-4ca7-9fdb-3232d12cea71", 10);
                request.setAttribute("teSeZhiNan", teSeZhiNan);
                request.setAttribute("trip", trip);
                request.setAttribute("daysList", daysList);
                request.setAttribute("pageK", pageK);
                request.setAttribute("pageT", pageT);
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
            return "v1/trip/viewTrip";
        } else {
            return null;
        }

    }

    // 首页的行程
    @RequestMapping(value = "/trip.htm")
    public String trip(HttpServletRequest request, HttpServletResponse response) throws IOException {
        try {
            List<Content> tripList = contentBiz.getTripByChannel("a86de70a-2995-4add-aac2-06107ea3671a", 10);
            if (tripList.size() > 0) {
                String tripId = tripList.get(0).getTblId();
                Trip trip = tripBiz.selectTripById(tripId);
                Integer day = trip.getDays();
                List<TripDay> daysList = new ArrayList<TripDay>();
                for (int i = 1; i <= day; i++) {
                    TripDay tripDay = new TripDay();
                    tripDay.setDay(i);
                    daysList.add(tripDay);
                }
                request.setAttribute("trip", trip);
                request.setAttribute("daysList", daysList);
            }
            // 特色指南
            List<Content> teSeZhiNan = contentBiz.getTripByChannel("2c686273-d946-4ca7-9fdb-3232d12cea71", 10);
            request.setAttribute("teSeZhiNan", teSeZhiNan);
            // 攻略心得
            List<Content> gongLvXinDe = contentBiz.getTripByChannel("3bda6fe9-d282-48fa-af2b-6b0c71674326", 5);
            request.setAttribute("gongLvXinDe", gongLvXinDe);
            // 本周热评
            List<Content> benZhouRePing = contentBiz.getTripByChannel("a786bd54-0760-4390-a079-2c38dc7e211f", 5);
            request.setAttribute("benZhouRePing", benZhouRePing);
            // 精彩热评
            List<Content> jingCaiRePing = contentBiz.getTripByChannel("f2e289c5-b0ee-42b7-99c7-df3605d91a88", 5);
            request.setAttribute("jingCaiRePing", jingCaiRePing);
            // 热门推荐
            List<Content> reMenTuiJian = contentBiz.getTripByChannel("6e8ccf59-62d9-46e7-a1d1-7c98b4e863ea", 18);
            request.setAttribute("reMenTuiJian", reMenTuiJian);
            request.setAttribute("tripList", tripList);

        } catch (AppBusinessException e) {
            e.printStackTrace();
        }
        return "v1/trip/trip";
    }

    // 查看地图
    @RequestMapping(value = "/viewMap.htm")
    public String viewMap(String lng, String lat, HttpServletRequest request, HttpServletResponse response) throws IOException {

        request.setAttribute("lng", lng);
        request.setAttribute("lat", lat);
        return "v1/trip/viewMap";
    }

    // 查看地图
    @RequestMapping(value = "/seeMap.htm")
    public String seeMap(String owner, String type, HttpServletRequest request, HttpServletResponse response) throws IOException {
        try {
            if (type.equals("hotel")) {
                // 酒店
                Hotel hotel = hotelRoomBiz.getHotelById(owner);
                request.setAttribute("lng", hotel.getLng());
                request.setAttribute("lat", hotel.getLat());
            } else if (type.equals("att")) {
                // 景点
                Scenic scenic = scenicBiz.getScenicById(owner);
                request.setAttribute("lng", scenic.getLng());
                request.setAttribute("lat", scenic.getLat());
            } else if (type.equals("product")) {
                // 产品
                Product product = productBiz.getProductById(owner);
                request.setAttribute("lng", product.getLng());
                request.setAttribute("lat", product.getLat());

            }
        } catch (AppBusinessException e) {
            e.printStackTrace();
        }
        return "v1/trip/viewMap";
    }

    // 更新行程
    @RequestMapping(value = "/updateMyTrip.htm")
    public String updateTrip(Trip trip, String tripDayList, HttpServletRequest request, HttpServletResponse response) throws IOException {

        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            response.setContentType("text/plain; charset=utf-8");
            PrintWriter pw = null;
            try {
                // 行程
                tripBiz.updateTrip(trip);
                tripBiz.deleteAllDay(trip.getId());
                JSONArray tripDayListArray = JSONArray.fromObject(tripDayList);
                for (Object object : tripDayListArray) {
                    // 行程时间内容
                    JSONObject jsonObj = JSONObject.fromObject(object);
                    TripDay tripDay = (TripDay) JSONObject.toBean(jsonObj, TripDay.class);
                    tripDay.setTripId(trip.getId());
                    tripBiz.insterTripDay(tripDay);
                }
                pw = response.getWriter();
                pw.print("success");
            }

            catch (AppBusinessException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    @RequestMapping(value = "/checkLogin.htm")
    public String checkMemberLogin(HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("text/plain; charset=utf-8");
        try {
            OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
            if (!Common.empty(onLineUserListener)) {
                Member member = onLineUserListener.getMember();
                if (!Common.empty(member)) {
                    response.getWriter().print("logged");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping(value = "/tripV.htm")
    public String tripV(String id, HttpServletRequest request, HttpServletResponse response) throws IOException {
        try {
            List<Content> tripList = contentBiz.getTripByChannel("a86de70a-2995-4add-aac2-06107ea3671a", 10);
            Trip trip = tripBiz.selectTripById(id);
            Integer day = trip.getDays();
            List<TripDay> daysList = new ArrayList<TripDay>();
            for (int i = 1; i <= day; i++) {
                TripDay tripDay = new TripDay();
                tripDay.setDay(i);
                daysList.add(tripDay);
            }
            // 特色指南
            List<Content> teSeZhiNan = contentBiz.getTripByChannel("2c686273-d946-4ca7-9fdb-3232d12cea71", 10);
            request.setAttribute("teSeZhiNan", teSeZhiNan);
            // 攻略心得
            List<Content> gongLvXinDe = contentBiz.getTripByChannel("3bda6fe9-d282-48fa-af2b-6b0c71674326", 5);
            request.setAttribute("gongLvXinDe", gongLvXinDe);
            // 本周热评
            List<Content> benZhouRePing = contentBiz.getTripByChannel("a786bd54-0760-4390-a079-2c38dc7e211f", 5);
            request.setAttribute("benZhouRePing", benZhouRePing);
            // 精彩热评
            List<Content> jingCaiRePing = contentBiz.getTripByChannel("f2e289c5-b0ee-42b7-99c7-df3605d91a88", 5);
            request.setAttribute("jingCaiRePing", jingCaiRePing);
            // 热门推荐
            List<Content> reMenTuiJian = contentBiz.getTripByChannel("6e8ccf59-62d9-46e7-a1d1-7c98b4e863ea", 18);
            request.setAttribute("reMenTuiJian", reMenTuiJian);
            request.setAttribute("tripList", tripList);
            request.setAttribute("trip", trip);
            request.setAttribute("daysList", daysList);
        } catch (AppBusinessException e) {
            e.printStackTrace();
        }
        return "v1/trip/tripv";
    }

    // 收藏分页
    @RequestMapping(value = "/myKeepPage.htm")
    public String myKeepPage(Integer pageK, HttpServletRequest request, HttpServletResponse response) throws IOException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            try {
                if (pageK == null || pageK == 0)
                    pageK = 1;
                Integer pagesize = 5;
                PageModel keepModel = memberBiz.getKeepListByMid(pageK, pagesize, onLineUserListener.getMember().getId());
                request.setAttribute("keepModel", keepModel);
                request.setAttribute("pageK", pageK);
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
            return "v1/trip/myKeepPage";
        } else {
            return null;
        }
    }

    // 我的行程分页
    @RequestMapping(value = "/myTripPage.htm")
    public String myTripPage(Integer pageT, HttpServletRequest request, HttpServletResponse response) throws IOException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            try {
                if (pageT == null || pageT == 0)
                    pageT = 1;
                Integer pagesize = 5;
                PageModel tripModel = tripBiz.getTripListByMid(pageT, pagesize, onLineUserListener.getMember().getId());
                request.setAttribute("tripModel", tripModel);
                request.setAttribute("pageT", pageT);
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
            return "v1/trip/myTripPage";
        } else {
            return null;
        }
    }

    /**
     * 增加取票人
     */
    @RequestMapping(value = "/newPerson.htm")
    public String newPerson(MemberTicker memberTicker, HttpServletRequest request, HttpServletResponse response) throws IOException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            memberTicker.setMemberId(onLineUserListener.getMember().getId());
            try {
                response.setContentType("text/plain; charset=utf-8");
                PrintWriter pw = null;
                memberTicker.setId(idBiz.generateId("coolsk_member_ticker"));
                memberTicker.setMemberId(onLineUserListener.getMember().getId());
                memberBiz.insterMemberTicker(memberTicker);
                pw = response.getWriter();
                pw.print("success");
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    /**
     * 修改取票人
     */
    @RequestMapping(value = "/updatePerson.htm")
    public String updatePerson(MemberTicker memberTicker, HttpServletRequest request, HttpServletResponse response) throws IOException {

        try {
            response.setContentType("text/plain; charset=utf-8");
            PrintWriter pw = null;
            memberBiz.updateMemberTicker(memberTicker);
            pw = response.getWriter();
            pw.print("success");
        } catch (AppBusinessException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 修改本人
     */
    @RequestMapping(value = "/updateUser.htm")
    public String updateUser(Member member, HttpServletRequest request, HttpServletResponse response) throws IOException {
        try {
            response.setContentType("text/plain; charset=utf-8");
            PrintWriter pw = null;
            memberBiz.update(member);
            pw = response.getWriter();
            pw.print("success");
        } catch (AppBusinessException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 删除取票人
     * 
     */
    @RequestMapping(value = "/deleteTicker.htm")
    public String deleteTicker(String id, HttpServletRequest request, HttpServletResponse response) throws IOException {
        try {
            response.setContentType("text/plain; charset=utf-8");
            PrintWriter pw = null;
            memberBiz.deleteTicker(id);
            pw = response.getWriter();
            pw.print("success");
        } catch (AppBusinessException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 
     */
    @RequestMapping(value = "/tickerLeft.htm")
    public String tickerLeft(HttpServletRequest request, HttpServletResponse response) throws IOException {
        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {
            try {
                List<MemberTicker> tickerList = memberBiz.getTickerListById(onLineUserListener.getMember().getId());
                request.setAttribute("tickerList", tickerList);
                Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
                request.setAttribute("member", member);
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
            return "v1/member/tickerLeft";
        } else {
            return null;
        }
    }

    // findDis
    @RequestMapping(value = "/findDis.htm")
    public String findDis(Integer page, String obj, String title, HttpServletRequest request, HttpServletResponse response) throws IOException {

        if (page == null)
            page = 1;
        try {
            if (obj != null && !obj.equals("")) {
                if (obj.equals("hotel")) {
                    PageModel hotelModle = hotelRoomBiz.searchHotel(page, null, title, null, null, null);
                    request.setAttribute("searchModle", hotelModle);
                    request.setAttribute("obj", obj);
                    request.setAttribute("title", title);
                } else if (obj.equals("scenic")) {
                    PageModel scenicModle = scenicBiz.getScenic(page, 10, title);
                    request.setAttribute("searchModle", scenicModle);
                    request.setAttribute("obj", "att");
                    request.setAttribute("title", title);
                }
            }
        } catch (AppBusinessException e) {
            e.printStackTrace();
        }

        return "v1/disCmt/findDis";
    }

    // findDis
    @RequestMapping(value = "/loginUp.htm")
    public String loginUp(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String hisUrl = request.getHeader("Referer");
        request.setAttribute("hisUrl", hisUrl);
        //System.out.println(hisUrl);
        return "loginUp";
    }

    // 注册成功
    @RequestMapping(value = "/rSuccess.htm")
    public String rSuccess(HttpServletRequest request, HttpServletResponse response) throws IOException {

        OnLineUserListener onLineUserListener = (OnLineUserListener) request.getSession().getAttribute("onlineUser");
        if (onLineUserListener != null) {

            try {
                Member member = memberBiz.getMemberById(onLineUserListener.getMember().getId());
                request.setAttribute("member", member);
                return "v1/member/rSuccess";
            } catch (AppBusinessException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    //邮箱验证成功
    @RequestMapping(value = "/successValede.htm", method = RequestMethod.GET)
    public String successValede(String number, HttpServletRequest request, HttpServletResponse response) throws AppBusinessException {
        try {
            Member member = memberBiz.getMemberById(number);
            if (member == null) {
                return "v1/common/error";
            } else {

                if (!member.getIsActive()) {
                    member.setIsActive(true);
                    memberBiz.update(member);
                    request.getSession(true).setAttribute("onlineUser", new OnLineUserListener(member));
                    request.setAttribute("member", member);
                    return "v1/member/emailValide";
                } else {
                    return "login";
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return "v1/common/error";
        }
    }

    // findPwdA
    @RequestMapping(value = "/fPwdA.htm")
    public String findPwdA(HttpServletRequest request, HttpServletResponse response) throws IOException {

        return "v1/member/findPwdA";
    }

    // findPwdB
    @RequestMapping(value = "/fPwdB.htm")
    public String findPwdB(HttpServletRequest request, HttpServletResponse response) throws IOException {

        return "v1/member/findPwdB";
    }

    // findPwdC
    @RequestMapping(value = "/fmyPwd.htm")
    public String findPwdC(String key, String number, HttpServletRequest request, HttpServletResponse response) throws IOException {
        try {
            if (Common.notEmptyStr(number) && Common.notEmptyStr(key)) {
                Member member = memberBiz.getMemberById(number);
                String rpFlag = member.getResetPassword();
                // 验证数据正确性
                if (Common.notEmptyStr(rpFlag) && rpFlag.split("@").length == 3) {
                    String[] dbFlag = rpFlag.split("@");
                    String dbKey = dbFlag[0];
                    String isBoolean = dbFlag[1];
                    long date = Long.parseLong(dbFlag[2]);
                    long minutes = ((new Date()).getTime() - date) / (1000 * 60);
                    if (key.equals(dbKey) && "true".equals(isBoolean) && minutes < 10) {
                        request.getSession(true).setAttribute("onlineUser", new OnLineUserListener(member));
                        member.setResetPassword("false");
                        memberBiz.update(member);
                        return "v1/member/findPwdC";
                    }
                }
            }
            return "login";
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    /**
     * 邮箱验证（密码找回）
     * 
     * @param request
     * @param response
     * @throws AppBusinessException
     */
    @RequestMapping(value = "/findEmail.htm")
    public void findEmail(HttpServletRequest request, HttpServletResponse response) throws AppBusinessException {
        String email = request.getParameter("email");
        if (Common.empty(email))
            return;
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter pw = null;
        try {
            pw = response.getWriter();
            Member m = memberBiz.getMemberEmail(email);
            if (m == null) {
                pw.print(false);
            } else {
                pw.print(true);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    //发送找回密码的邮箱

    @RequestMapping(value = "/findPwdEmail.htm", method = RequestMethod.POST)
    public String findPwdEmail(String vCode, String email, HttpServletRequest request, HttpServletResponse response) throws IOException {
        try {
            response.setContentType("text/html; charset=UTF-8");
            PrintWriter out = response.getWriter();
            String sessionCode = String.valueOf(request.getSession().getAttribute("code"));
            if (Common.notEmptyStr(vCode) && !vCode.equals(sessionCode)) {
                out.print("codeError");
                return null;
            }
            Member member = memberBiz.getMemberEmail(email);
            if (member != null) {
                // 设置验证有效性---第一个是key第二个是标记有效性第三个是时间有效性
                long date = new Date().getTime();
                String key = UUID.randomUUID().toString();
                String flag = key + "@true@" + date;

                String path = request.getContextPath();
                String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
                String title = "爽客密码找回";
                String emailContent = member.getUsername() + "您好：<br /><br />" + "您在爽客上申请了找回密码，请点击以下链接进行密码重置：<br />" + "<a href='" + basePath
                                      + "fmyPwd.htm?key=" + key + "&number=" + member.getId() + "'>" + basePath + "fmyPwd.htm.htm?key=" + key + "&number="
                                      + member.getId() + "</a>" + "<br />如果以上链接无法点击，请将上面的地址复制到你的浏览器的地址输入框(如IE)的地址栏进行验证。<br />"
                                      + "为保障你账号的安全性，以上链接有效期为10分钟，并将在你点击一次后失效！<br /><br />" + "--爽客";
                mailBiz.sendEmail(basePath, member, title, emailContent);
                member.setResetPassword(flag);
                memberBiz.update(member);
                out.print("success");
            } else {
                out.print("error");
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    //取消收藏
    @RequestMapping(value = "/cancelMykeep.htm")
    public String cancelMykeep(String id, HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html; charset=UTF-8");
        PrintWriter pw = null;
        try {
            memberBiz.deleteKeepByid(id);
            pw = response.getWriter();
            pw.print("success");
        } catch (Exception e) {
            pw = response.getWriter();
            pw.print("error");
            if (logger.isErrorEnabled()) {
                logger.error("get order failure.", e);
            }
        }
        return null;
    }

    @RequestMapping(value = "/checkTicketLogin.htm")
    public void checkTicketLogin(String member, HttpServletRequest request, HttpServletResponse response) throws AppBusinessException {
        if (member == null)
            return;
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter pw = null;
        try {
            pw = response.getWriter();
            Member m = memberBiz.getMemberById(member);
            if (Common.empty(m)) {
                pw.print(false);
            } else {
                pw.print(true);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}